﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Quebec.Silverlight.Controls
{
    public class StackPanel : System.Windows.Controls.StackPanel
    {
        public Thickness ItemMargin
        {
            get
            {
                return (Thickness)GetValue(ItemMarginProperty);
            }
            set
            {
                SetValue(ItemMarginProperty, value);
            }
        }
        public static readonly DependencyProperty ItemMarginProperty =
            DependencyProperty.Register(
                "ItemMargin",
                typeof(Thickness), 
                typeof(StackPanel),
                null);

        public StackPanel()
        {
            this.Loaded += OnLoaded;
        }

        void OnLoaded(object sender, RoutedEventArgs e)
        {
            foreach (UIElement element in this.Children)
            {
                if (element is FrameworkElement)
                {
                    ((FrameworkElement)element).Margin = ItemMargin;
                }
            }

            this.InvalidateArrange();
        }
    }
}
